package org.xa3apm.vote.hibernate.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * Entity implementation class for Entity: Address
 * 
 */
@Entity
@Table(name = "tAddress")
@NamedQueries({
		@NamedQuery(name = "Address.getById", query = "SELECT A FROM Address A WHERE A.id = :id"),
		@NamedQuery(name = "Address.getAll", query = "SELECT A FROM Address A") })
public class Address implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	@Column(name = "id")
	private Long id;
	@ManyToOne(targetEntity = Settlement.class)
	private Settlement settlements;
	@Column(name = "street")
	private String street;
	@Column(name = "complex")
	private String complex;
	@Column(name = "number")
	private Integer number;
	@OneToOne
	private Person person;

	public Address() {
		super();
	}

	public Address(Settlement settlement, String street, String complex,
			Integer number, Person person) {
		super();
		this.settlements = settlement;
		this.street = street;
		this.complex = complex;
		this.number = number;
		this.person = person;
	}

	/**
	 * @return the id
	 */
	public final Long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public final void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the settlements
	 */
	public final Settlement getSettlements() {
		return settlements;
	}

	/**
	 * @param settlements
	 *            the settlements to set
	 */
	public final void setSettlements(Settlement settlements) {
		this.settlements = settlements;
	}

	/**
	 * @return the street
	 */
	public final String getStreet() {
		return street;
	}

	/**
	 * @param street
	 *            the street to set
	 */
	public final void setStreet(String street) {
		this.street = street;
	}

	/**
	 * @return the complex
	 */
	public final String getComplex() {
		return complex;
	}

	/**
	 * @param complex
	 *            the complex to set
	 */
	public final void setComplex(String complex) {
		this.complex = complex;
	}

	/**
	 * @return the number
	 */
	public final Integer getNumber() {
		return number;
	}

	/**
	 * @param number
	 *            the number to set
	 */
	public final void setNumber(Integer number) {
		this.number = number;
	}

	/**
	 * @return the person
	 */
	public final Person getPerson() {
		return person;
	}

	/**
	 * @param person
	 *            the person to set
	 */
	public final void setPerson(Person person) {
		this.person = person;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((complex == null) ? 0 : complex.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((number == null) ? 0 : number.hashCode());
		result = prime * result
				+ ((person == null) ? 0 : person.getId().hashCode());
		result = prime * result
				+ ((settlements == null) ? 0 : settlements.hashCode());
		result = prime * result + ((street == null) ? 0 : street.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Address)) {
			return false;
		}
		Address other = (Address) obj;
		if (complex == null) {
			if (other.complex != null) {
				return false;
			}
		} else if (!complex.equals(other.complex)) {
			return false;
		}
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		if (number == null) {
			if (other.number != null) {
				return false;
			}
		} else if (!number.equals(other.number)) {
			return false;
		}
		if (person == null) {
			if (other.person != null) {
				return false;
			}
		} else if (!person.getId().equals(other.person.getId())) {
			return false;
		}
		if (settlements == null) {
			if (other.settlements != null) {
				return false;
			}
		} else if (!settlements.equals(other.settlements)) {
			return false;
		}
		if (street == null) {
			if (other.street != null) {
				return false;
			}
		} else if (!street.equals(other.street)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "Address [id=" + id + ", settlementId=" + settlements.getId()
				+ ", street=" + street + ", complex=" + complex + ", number="
				+ number + ", personId=" + person.getId() + "]";
	}
}
